package com.hangzhou.xyj.ui.dialog;


import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.hangzhou.xyj.R;
import com.hangzhou.xyj.utils.StringUtil;
import com.hangzhou.xyj.utils.ToastUtil;

/**
 * 输入设备名称对话框
 *
 * @author neo.duan
 */
public class InputDramaNameDialog extends Dialog implements View.OnClickListener {
    private TextView mTvTitle;
    private EditText mEdtInput;
    private Button mBtnPositive;
    private Button mBtnNegative;

    private View.OnClickListener mPositiveListener;
    private View.OnClickListener mNegativeListener;

    public InputDramaNameDialog(Context context) {
        super(context, R.style.MyDialogStyle);

        setCanceledOnTouchOutside(false);
        setContentView(R.layout.layout_input_drama_name);

        initView();
        initListener();
        initData();
    }

    private void initView() {
        mTvTitle = (TextView) findViewById(R.id.tv_message);
        mEdtInput = (EditText) findViewById(R.id.edt_input_drama_name);
        mBtnPositive = (Button) findViewById(R.id.btn_positive);
        mBtnNegative = (Button) findViewById(R.id.btn_negative);
    }

    private void initListener() {
        mBtnPositive.setOnClickListener(this);
        mBtnNegative.setOnClickListener(this);
    }

    private void initData() {

    }

    public String getDramaName() {
        return mEdtInput.getText().toString().trim();
    }

    public void setDramaName(String name) {
        if (StringUtil.isBlank(name)) {
            mEdtInput.setText("");
            return;
        }
        mEdtInput.setText(name);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_positive:
                if (StringUtil.isBlank(getDramaName())) {
                    ToastUtil.show("请输入戏曲名称");
                    return;
                }
                if (mPositiveListener != null) {
                    mPositiveListener.onClick(v);
                }
                break;
            case R.id.btn_negative:
                if (mNegativeListener != null) {
                    mNegativeListener.onClick(v);
                }
                break;
        }
    }

    public void setPositiveListener(View.OnClickListener listener) {
        this.mPositiveListener = listener;
    }

    public void setNegativeListener(View.OnClickListener listener) {
        this.mNegativeListener = listener;
    }
}
